package com.gxa.controller;

import com.gxa.pojo.Goods;
import com.gxa.pojo.GoodsClass;
import com.gxa.pojo.Pll;
import com.gxa.service.GoodsService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: zrf
 * Date: 2020/11/26 9:16
 * Description:
 * Version: V1.0
 */
@Controller
@RequestMapping("/goods")
@Api(value = "商品管理",tags = "商品管理Api")
public class GoodsController {
    @Autowired(required = false)
    private GoodsService goodsService;
    @Autowired(required = false)
    private ResponseData responseData;
    /**
     * 查询所有商品信息，按时间倒序
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/queryGoods",method = RequestMethod.GET)
    @ApiOperation(value = "查询未商品信息",notes = "查询未商品信息",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData queryGoods(){

        List<Map> mapList =goodsService.queryGoods();

        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }

        return responseData;
    }
    @RequestMapping(value = "/updateGoods",method = RequestMethod.POST)
    @ApiOperation(value = "修改商品信息",notes = "修改商品信息",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData updateGoods(Goods goods){
        int result = goodsService.updateGoods(goods);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/delGoods",method = RequestMethod.GET)
    @ApiOperation(value = "删除商品信息",notes = "删除商品信息",httpMethod = "GET", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", paramType = "query"),
    })
    @ResponseBody
    public ResponseData delGoods(@RequestParam int goodsId){
        int result = goodsService.delGoods(goodsId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/hszGoods",method = RequestMethod.GET)
    @ApiOperation(value = "将商品加入回收站",notes = "将商品加入回收站",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData hszGoods(Integer[] goodsId){
        int result = goodsService.hszGoods(goodsId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/selGoods",method = RequestMethod.POST)
    @ApiOperation(value = "搜索商品",notes = "搜索商品",httpMethod = "POST", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "number", value = "商品货号", paramType = "query"),
            @ApiImplicitParam(name = "goodsName", value = "商品名称", paramType = "query"),
            @ApiImplicitParam(name = "goodsCname", value = "商品分类名称", paramType = "query"),
    })
    @ResponseBody
    public ResponseData selGoods(@RequestParam String goodscname, @RequestParam int number, @RequestParam String goodsCname){
        List<Map> mapList =goodsService.SelGoods(goodscname,number,goodsCname);
        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @RequestMapping(value = "/addGoods",method = RequestMethod.POST)
    @ApiOperation(value = "加入商品",notes = "加入商品",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData addGoods(Goods goods){
        int result = goodsService.addGoods(goods);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/queryGoodsUn",method = RequestMethod.GET)
    @ApiOperation(value = "商品回收站",notes = "商品回收站",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData queryGoodsUn(){
        List<Map> mapList =goodsService.queryGoodsUn();

        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }

        return responseData;
    }
    @RequestMapping(value = "/queryGoodsClass",method = RequestMethod.GET)
    @ApiOperation(value = "商品分类",notes = "商品分类",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData queryGoodsClass(){
        List<Map> mapList =goodsService.queryGoodsClass();

        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }

        return responseData;
    }
    @RequestMapping(value = "/updateGoodsClSt",method = RequestMethod.GET)
    @ApiOperation(value = "更改商品分类显示状态",notes = "更改商品分类显示状态",httpMethod = "GET", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsCid", value = "商品分类id", paramType = "query"),
    })
    @ResponseBody
    public ResponseData updateGoodsClSt(int goodsCid){
        int result = goodsService.updateGoodsClSt(goodsCid);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/updateGoodsClass",method = RequestMethod.POST)
    @ApiOperation(value = "修改商品分类",notes = "修改商品分类",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData updateGoodsClass(GoodsClass goodsClass){
        int result = goodsService.updateGoodsClass(goodsClass);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @RequestMapping(value = "/delGoodsClass",method = RequestMethod.GET)
    @ApiOperation(value = "删除商品分类",notes = "删除商品分类",httpMethod = "GET", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsCid", value = "商品分类id", paramType = "query"),
    })
    @ResponseBody
    public ResponseData delGoodsClass(int goodsCid){
        int result = goodsService.delGoodsClass(goodsCid);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @RequestMapping(value = "/addGoodsClass",method = RequestMethod.POST)
    @ApiOperation(value = "添加商品分类",notes = "添加商品分类",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData addGoodsClass(GoodsClass goodsClass){
        int result = goodsService.addGoodsClass(goodsClass);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @RequestMapping(value = "/qureyPll",method = RequestMethod.GET)
    @ApiOperation(value = "商品标签",notes = "商品标签",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData qureyPll(){
        List<Map> mapList =goodsService.qureyPll();
        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/updatePllSt",method = RequestMethod.GET)
    @ApiOperation(value = "更改商品标签使用状态",notes = "更改商品标签使用状态",httpMethod = "GET", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pllId", value = "商品标签id", paramType = "query"),
    })
    @ResponseBody
    public ResponseData updatePllSt(int pllId){
        int result = goodsService.updatePllSt(pllId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @RequestMapping(value = "/updatePll",method = RequestMethod.POST)
    @ApiOperation(value = "修改商品标签",notes = "修改商品标签",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData updatePll(Pll pll){
        int result = goodsService.updatePll(pll);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/addPll",method = RequestMethod.POST)
    @ApiOperation(value = "添加商品标签",notes = "添加商品标签",httpMethod = "POST", response = ResponseData.class)
    @ResponseBody
    public ResponseData addPll(Pll pll){
        int result = goodsService.addPll(pll);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/qureyPr",method = RequestMethod.GET)
    @ApiOperation(value = "商品评论",notes = "商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData qureyPr(){
        List<Map> mapList =goodsService.qureyPr();
        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/selPr",method = RequestMethod.GET)
    @ApiOperation(value = "搜索商品评论",notes = "搜索商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData selPr(String prComments){
        List<Map> mapList =goodsService.selPr(prComments);
        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/delPr",method = RequestMethod.GET)
    @ApiOperation(value = "删除商品评论",notes = "删除商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData delPr(Integer[] prId){
        int result = goodsService.delPr(prId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/updPr",method = RequestMethod.GET)
    @ApiOperation(value = "允许显示商品评论",notes = "允许显示商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData updPr(Integer[] prId){
        int result = goodsService.updPr(prId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/updPrUn",method = RequestMethod.GET)
    @ApiOperation(value = "禁止显示商品评论",notes = "禁止显示商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData updPrUn(Integer[] prId){
        int result = goodsService.updPrUn(prId);
        if(result > 0){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(null);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
    @RequestMapping(value = "/qureyPrUn",method = RequestMethod.GET)
    @ApiOperation(value = "显示隐藏的商品评论",notes = "显示隐藏的商品评论",httpMethod = "GET", response = ResponseData.class)
    @ResponseBody
    public ResponseData qureyPrUn(){
        List<Map> mapList =goodsService.qureyPrUn();
        if(mapList != null){
            responseData.setCode(200);
            responseData.setMsg("成功");
            responseData.setData(mapList);
        }else{
            responseData.setCode(400);
            responseData.setMsg("失败");
            responseData.setData(null);
        }
        return responseData;
    }
}
